/*
 *
 *    Copyright (c) 2022 Project CHIP Authors
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

// THIS FILE IS GENERATED BY ZAP
// This file is generated from clusters-Structs.ipp.zapt

#include <clusters/PushAvStreamTransport/Structs.h>

#include <app/data-model/StructDecodeIterator.h>
#include <app/data-model/WrappedStructEncoder.h>

namespace chip {
namespace app {
namespace Clusters {
namespace PushAvStreamTransport {
namespace Structs {

namespace TransportMotionTriggerTimeControlStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kInitialDuration), initialDuration);
    encoder.Encode(to_underlying(Fields::kAugmentationDuration), augmentationDuration);
    encoder.Encode(to_underlying(Fields::kMaxDuration), maxDuration);
    encoder.Encode(to_underlying(Fields::kBlindDuration), blindDuration);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kInitialDuration))
        {
            err = DataModel::Decode(reader, initialDuration);
        }
        else if (__context_tag == to_underlying(Fields::kAugmentationDuration))
        {
            err = DataModel::Decode(reader, augmentationDuration);
        }
        else if (__context_tag == to_underlying(Fields::kMaxDuration))
        {
            err = DataModel::Decode(reader, maxDuration);
        }
        else if (__context_tag == to_underlying(Fields::kBlindDuration))
        {
            err = DataModel::Decode(reader, blindDuration);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace TransportMotionTriggerTimeControlStruct

namespace TransportZoneOptionsStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kZone), zone);
    encoder.Encode(to_underlying(Fields::kSensitivity), sensitivity);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kZone))
        {
            err = DataModel::Decode(reader, zone);
        }
        else if (__context_tag == to_underlying(Fields::kSensitivity))
        {
            err = DataModel::Decode(reader, sensitivity);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace TransportZoneOptionsStruct

namespace TransportTriggerOptionsStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kTriggerType), triggerType);
    encoder.Encode(to_underlying(Fields::kMotionZones), motionZones);
    encoder.Encode(to_underlying(Fields::kMotionSensitivity), motionSensitivity);
    encoder.Encode(to_underlying(Fields::kMotionTimeControl), motionTimeControl);
    encoder.Encode(to_underlying(Fields::kMaxPreRollLen), maxPreRollLen);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kTriggerType))
        {
            err = DataModel::Decode(reader, triggerType);
        }
        else if (__context_tag == to_underlying(Fields::kMotionZones))
        {
            err = DataModel::Decode(reader, motionZones);
        }
        else if (__context_tag == to_underlying(Fields::kMotionSensitivity))
        {
            err = DataModel::Decode(reader, motionSensitivity);
        }
        else if (__context_tag == to_underlying(Fields::kMotionTimeControl))
        {
            err = DataModel::Decode(reader, motionTimeControl);
        }
        else if (__context_tag == to_underlying(Fields::kMaxPreRollLen))
        {
            err = DataModel::Decode(reader, maxPreRollLen);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace TransportTriggerOptionsStruct

namespace CMAFContainerOptionsStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kCMAFInterface), CMAFInterface);
    encoder.Encode(to_underlying(Fields::kSegmentDuration), segmentDuration);
    encoder.Encode(to_underlying(Fields::kChunkDuration), chunkDuration);
    encoder.Encode(to_underlying(Fields::kSessionGroup), sessionGroup);
    encoder.Encode(to_underlying(Fields::kTrackName), trackName);
    encoder.Encode(to_underlying(Fields::kCENCKey), CENCKey);
    encoder.Encode(to_underlying(Fields::kCENCKeyID), CENCKeyID);
    encoder.Encode(to_underlying(Fields::kMetadataEnabled), metadataEnabled);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kCMAFInterface))
        {
            err = DataModel::Decode(reader, CMAFInterface);
        }
        else if (__context_tag == to_underlying(Fields::kSegmentDuration))
        {
            err = DataModel::Decode(reader, segmentDuration);
        }
        else if (__context_tag == to_underlying(Fields::kChunkDuration))
        {
            err = DataModel::Decode(reader, chunkDuration);
        }
        else if (__context_tag == to_underlying(Fields::kSessionGroup))
        {
            err = DataModel::Decode(reader, sessionGroup);
        }
        else if (__context_tag == to_underlying(Fields::kTrackName))
        {
            err = DataModel::Decode(reader, trackName);
        }
        else if (__context_tag == to_underlying(Fields::kCENCKey))
        {
            err = DataModel::Decode(reader, CENCKey);
        }
        else if (__context_tag == to_underlying(Fields::kCENCKeyID))
        {
            err = DataModel::Decode(reader, CENCKeyID);
        }
        else if (__context_tag == to_underlying(Fields::kMetadataEnabled))
        {
            err = DataModel::Decode(reader, metadataEnabled);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace CMAFContainerOptionsStruct

namespace ContainerOptionsStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kContainerType), containerType);
    encoder.Encode(to_underlying(Fields::kCMAFContainerOptions), CMAFContainerOptions);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kContainerType))
        {
            err = DataModel::Decode(reader, containerType);
        }
        else if (__context_tag == to_underlying(Fields::kCMAFContainerOptions))
        {
            err = DataModel::Decode(reader, CMAFContainerOptions);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace ContainerOptionsStruct

namespace TransportOptionsStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kStreamUsage), streamUsage);
    encoder.Encode(to_underlying(Fields::kVideoStreamID), videoStreamID);
    encoder.Encode(to_underlying(Fields::kAudioStreamID), audioStreamID);
    encoder.Encode(to_underlying(Fields::kTLSEndpointID), TLSEndpointID);
    encoder.Encode(to_underlying(Fields::kUrl), url);
    encoder.Encode(to_underlying(Fields::kTriggerOptions), triggerOptions);
    encoder.Encode(to_underlying(Fields::kIngestMethod), ingestMethod);
    encoder.Encode(to_underlying(Fields::kContainerOptions), containerOptions);
    encoder.Encode(to_underlying(Fields::kExpiryTime), expiryTime);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kStreamUsage))
        {
            err = DataModel::Decode(reader, streamUsage);
        }
        else if (__context_tag == to_underlying(Fields::kVideoStreamID))
        {
            err = DataModel::Decode(reader, videoStreamID);
        }
        else if (__context_tag == to_underlying(Fields::kAudioStreamID))
        {
            err = DataModel::Decode(reader, audioStreamID);
        }
        else if (__context_tag == to_underlying(Fields::kTLSEndpointID))
        {
            err = DataModel::Decode(reader, TLSEndpointID);
        }
        else if (__context_tag == to_underlying(Fields::kUrl))
        {
            err = DataModel::Decode(reader, url);
        }
        else if (__context_tag == to_underlying(Fields::kTriggerOptions))
        {
            err = DataModel::Decode(reader, triggerOptions);
        }
        else if (__context_tag == to_underlying(Fields::kIngestMethod))
        {
            err = DataModel::Decode(reader, ingestMethod);
        }
        else if (__context_tag == to_underlying(Fields::kContainerOptions))
        {
            err = DataModel::Decode(reader, containerOptions);
        }
        else if (__context_tag == to_underlying(Fields::kExpiryTime))
        {
            err = DataModel::Decode(reader, expiryTime);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace TransportOptionsStruct

namespace TransportConfigurationStruct {
CHIP_ERROR Type::EncodeForWrite(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    return DoEncode(aWriter, aTag, NullOptional);
}

CHIP_ERROR Type::EncodeForRead(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIndex aAccessingFabricIndex) const
{
    return DoEncode(aWriter, aTag, MakeOptional(aAccessingFabricIndex));
}

CHIP_ERROR Type::DoEncode(TLV::TLVWriter & aWriter, TLV::Tag aTag, const Optional<FabricIndex> & aAccessingFabricIndex) const
{

    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };

    encoder.Encode(to_underlying(Fields::kConnectionID), connectionID);
    encoder.Encode(to_underlying(Fields::kTransportStatus), transportStatus);
    encoder.Encode(to_underlying(Fields::kTransportOptions), transportOptions);
    if (aAccessingFabricIndex.HasValue())
    {
        encoder.Encode(to_underlying(Fields::kFabricIndex), fabricIndex);
    }

    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kConnectionID))
        {
            err = DataModel::Decode(reader, connectionID);
        }
        else if (__context_tag == to_underlying(Fields::kTransportStatus))
        {
            err = DataModel::Decode(reader, transportStatus);
        }
        else if (__context_tag == to_underlying(Fields::kTransportOptions))
        {
            err = DataModel::Decode(reader, transportOptions);
        }
        else if (__context_tag == to_underlying(Fields::kFabricIndex))
        {
            err = DataModel::Decode(reader, fabricIndex);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace TransportConfigurationStruct

namespace SupportedFormatStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kContainerFormat), containerFormat);
    encoder.Encode(to_underlying(Fields::kIngestMethod), ingestMethod);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kContainerFormat))
        {
            err = DataModel::Decode(reader, containerFormat);
        }
        else if (__context_tag == to_underlying(Fields::kIngestMethod))
        {
            err = DataModel::Decode(reader, ingestMethod);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace SupportedFormatStruct
} // namespace Structs
} // namespace PushAvStreamTransport
} // namespace Clusters
} // namespace app
} // namespace chip
